package com.ymy.thinking.in.spring.bean.lifecycle;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.AnnotatedBeanDefinitionReader;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * {@link AnnotatedBeanDefinitionReader} 是面向 Java 类读取 Bean Definition
 *
 * @author Ringo
 * @date 2022/2/5 23:45
 */
public class AnnotatedBeanDefinitionReaderDemo {
    public static void main(String[] args) {
        // 实际上 AnnotatedBeanDefinitionReader 是 AnnotationConfigApplicationContext 中的一个属性
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();

        // 读取 BeanDefinition, 注册非 Component Class
        AnnotatedBeanDefinitionReader beanDefinitionReader = new AnnotatedBeanDefinitionReader(applicationContext);
        beanDefinitionReader.register(AnnotatedBeanDefinitionReaderDemo.class);

        // 启动 Spring 容器
        applicationContext.refresh();

        applicationContext.getBeanProvider(AnnotatedBeanDefinitionReaderDemo.class).ifAvailable(System.out::println);

        applicationContext.close();
    }
}
